using System.IO;
using System.Reflection;
using GrapeCity.Documents.Excel;
using System;
using System.Data;

namespace GrapeCity.Documents.Excel.Examples.Templates.TemplateSamples.MedicalReport
{
    class Program
    {
        static void Main(string[] args)
        {
			//create a new workbook
			var workbook = new GrapeCity.Documents.Excel.Workbook();
			
			//Load template file from resource
			var templateFile = GetResourceStream("xlsx\\Template_MedicalReport.xlsx");
			workbook.Open(templateFile);
			
			#region Init Data
			var datasource = new DataTable();
			datasource.Columns.Add(new DataColumn("Date", typeof(DateTime)));
			datasource.Columns.Add(new DataColumn("Time", typeof(TimeSpan)));
			datasource.Columns.Add(new DataColumn("Event", typeof(string)));
			datasource.Columns.Add(new DataColumn("Systolic", typeof(Int32)));
			datasource.Columns.Add(new DataColumn("Diastolic", typeof(Int32)));
			datasource.Columns.Add(new DataColumn("HeartRate", typeof(Int32)));
			datasource.Columns.Add(new DataColumn("Glucose", typeof(Int32)));
			datasource.Columns.Add(new DataColumn("Notes", typeof(string)));
			
			datasource.Rows.Add(DateTime.Today, new TimeSpan(6, 0, 0), "Wake", 129, 79, 72, 55, null);
			datasource.Rows.Add(DateTime.Today, new TimeSpan(7, 0, 0), "Before Meal", 120, 80, 74, 70, null);
			datasource.Rows.Add(DateTime.Today, new TimeSpan(9, 0, 0), "After Meal", 133, 80, 75, 75, null);
			datasource.Rows.Add(DateTime.Today, new TimeSpan(10, 0, 0), "BP only", 143, 91, 75, 190, null);
			datasource.Rows.Add(DateTime.Today, new TimeSpan(12, 0, 0), "Before Meal", 141, 84, 70, 140, null);
			datasource.Rows.Add(DateTime.Today, new TimeSpan(15, 0, 0), "After Meal", 132, 80, 68, 90, "Took BP medication with meal");
			
			#endregion
			
			//Init template global settings
			workbook.Names.Add("TemplateOptions.KeepLineSize", "true");
			workbook.Names.Add("TemplateOptions.InsertMode", "EntireRowColumn");
			
			//Add data source
			workbook.AddDataSource("ds", datasource);
			//Invoke to process the template
			workbook.ProcessTemplate();
			        
			// Save to an excel file
			workbook.Save("MedicalReport.xlsx");

        }

		static Stream GetResourceStream(string resourcePath)
        {
            string resource = "MedicalReport.Resource." + resourcePath.Replace("\\", ".");
            var assembly = typeof(Program).GetTypeInfo().Assembly;
            return assembly.GetManifestResourceStream(resource);
        }

    }
}